package com.mq.fair;

import com.mq.ConnectionUtils;
import com.rabbitmq.client.*;

import java.io.IOException;

public class RecverL2 {
		private static final String QUEUE_NAME = "test_L1_queue";

	public static void main(String[] args) throws Exception {
		//获取连接
		Connection connection = ConnectionUtils.getConnection();

		//创建频道
		Channel channel = connection.createChannel();

		//声明队列
		channel.queueDeclare(QUEUE_NAME,false,false,false,null);

		//定义队列的消费者
		Consumer consumer = new DefaultConsumer(channel) {
			@Override
			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
					throws IOException {
				String message = new String(body, "UTF-8");
				System.out.println("[2] recv msg" + message);

				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		};
		boolean autoAck = true;

		channel.basicConsume(QUEUE_NAME, autoAck, consumer);
	}
}